package com.whmskj.xjlhsc.mapper;

import com.whmskj.xjlhsc.entity.Shachangsbbanyield;
import com.whmskj.xjlhsc.entity.Shachangsbhouryield;
import com.whmskj.xjlhsc.service.dto.MaintenanceDataDTO;
import com.whmskj.xjlhsc.service.dto.MaintenanceRecordDTO;
import com.whmskj.xjlhsc.service.dto.StatusCountDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: Sakura
 * @Date: 2025/8/14 11:36
 * @Version: v1.0.0
 * @Description: TODO
 **/
@Mapper
public interface ScKbMapper {
    /**
     * 统计各状态数量
     * @return 状态统计结果
     */
    @Select("SELECT " +
            "SUM(CASE WHEN status = '运行' THEN 1 ELSE 0 END) AS running, " +
            "SUM(CASE WHEN status = '临停' THEN 1 ELSE 0 END) AS temporaryStop, " +
            "SUM(CASE WHEN status = '待机' THEN 1 ELSE 0 END) AS standby, " +
            "SUM(CASE WHEN status = '维保中' THEN 1 ELSE 0 END) AS maintenance, " +
            "SUM(CASE WHEN status = '离线' THEN 1 ELSE 0 END) AS offline " +
            "FROM sb02EquipmentCounterAccount")
    StatusCountDTO countStatus();

    @Select("SELECT y.*, a.workshop " +
            "FROM shachang_sb_dayyield y " +
            "LEFT JOIN sb02EquipmentCounterAccount a ON y.mesid = a.id " +
            "WHERE y.mesid IN (SELECT DISTINCT mesid FROM shachang_sb_dayyield)")
    List<Shachangsbhouryield> selectAll();

    @Select("SELECT day, shift, " +
            "SUM(CAST(`yieldkm` AS DECIMAL(18,2))) AS total_yield, " +
            "SUM(CAST(`actualyieldkm` AS DECIMAL(18,2))) AS total_actualyield " +
            "FROM shachang_sb_banyield " +
            "GROUP BY day, shift " +
            "ORDER BY day, shift")
    List<Shachangsbbanyield> selectGroupEfficiency(String startDate, String endDate);

    List<MaintenanceRecordDTO> getMaintenanceRecords();

    // 按日统计维保次数
    List<MaintenanceDataDTO> getDailyMaintenanceStats();

    // 按月统计维保次数
    List<MaintenanceDataDTO> getMonthlyMaintenanceStats();

    // 按年统计维保次数
    List<MaintenanceDataDTO> getYearlyMaintenanceStats();
}
